<?php
declare (strict_types=1);

namespace app\admin\controller;

use app\admin\model\Access;
use think\App;
use tree\Tree;

class Index extends Base
{
    protected $access = '';

    public function __construct(App $app, Access $access)
    {
        parent::__construct($app);
        $this->access = $access;
    }

    public function index(): string
    {
        $auth = $this->access->getAuth($this->authId);
        $result = $this->access->getMyAccess($this->authId);
        $menu = [];
        $access = [];
        foreach ($result as $item) {
            $access[$item['key']] = ['name' => $item['name'], 'url' => $item['url']];
            if ($item['menu']) {
                $menu[] = $item;
            }
        }

        $menu = Tree::makeTree($menu);

        if ($this->authId == 0) {
            $auth['name'] = '系统管理员';
        }

        $this->setAccess();
        $this->admin['auth_name'] = $auth['name'];
        $this->assign('admin', $this->admin);
        $this->assign('access',$access);
        $this->assign('menu', $menu);
        return $this->fetch('common/base');
    }

    public function home(): string
    {

        return $this->fetch();
    }
}
